<template>
	<view class="user">
		<view class="user-back"></view>

		<view class="user_box">
			<view class="author">
				<view class="flex-column flex-space-between img" style="width: 690rpx;">
					<view class="flex_left_right" v-if="userToken" @click="updateAvatar">
						<view class="align_center ">
							<block v-if="personInfo.avatar">
								<image src='../../static/img/avatar.png' class="avator" mode="aspectFill"
									v-if="personInfo.avatar.match('xml;base64')" />
								<image :src='personInfo.avatar' class="avator" mode="aspectFill" v-else />
							</block>

							<image src="../../static/img/avatar.png" class="avator" v-else />
							<view>
								<view style="display: flex;align-items: center;">
									<view>{{personInfo.nickname}}</view>
								</view>
								<view class="mobile">{{personInfo.mobile}}</view>

							</view>
						</view>
						<image src="@/static/img/set.png" class="set_img" mode="widthFix"></image>
					</view>
					<view class="align_center" v-else @click="isLogin">
						<image src="../../static/img/avatar.png" class="avator"></image>
						<text>登录/注册</text>
					</view>

					<view class="remain-money">
						<view @click="$project.toPath('/pages/coupons/moreCoupons')">
							<text class="fs-18 bold">{{personInfo.couponNum}}</text>
							<text class="fs-13">优惠券</text>
						</view>

						<view @click="$project.toPath('/pages/integral/detail')">
							<text class="fs-18 bold">{{personInfo.score}}</text>
							<text class="fs-13">积分</text>
						</view>
						<view @click="$doubleClick(remainPage)">
							<text class="fs-18 bold">{{personInfo.money}}</text>
							<text class="fs-13">余额</text>
						</view>
					</view>
				</view>
			</view>

			<view class="order-info">
				<view class="my-order flex_left_right" @click="orderShopPage({url:''})">
					<text class="">商城订单</text>
					<text class="iconfont iconfanhui t-180 gray_font"></text>
				</view>
				<view class="order-statu flex_left_right">
					<view v-for="(item,index) in shopStatu" :key="index" @click="orderShopPage(item)">
						<view class="center">
							<image :src="item.image" mode="aspectFit"></image>
							<text v-if="item.num" class="to-be-paid paid-red">{{item.num}}</text>
						</view>
						<view class="fs-13 center name">{{item.title}}</view>
					</view>
				</view>
			</view>

			<view class="order-info">
				<view class="my-order flex_left_right" @click="orderPage({url:''})">
					<text class="">服务订单</text>
					<text class="iconfont iconfanhui t-180 gray_font"></text>
				</view>
				<view class="order-statu flex_left_right">
					<view v-for="(item,index) in orderStatu" :key="index" @click="orderPage(item)">
						<view class="center">
							<image :src="item.image" mode="aspectFit"></image>
							<text v-if="item.num" class="to-be-paid">{{item.num}}</text>
						</view>
						<view class="fs-13 center name">{{item.title}}</view>
					</view>
				</view>
			</view>
			<view class="my-service">
				<view class="">更多功能</view>
				<view class="fu_box sign">
					<view v-for="(item,index) in service" :key="index" @click="pageUrl(item)">
						<image :src="item.image"></image>
						<text class="fs-13">{{item.title}}</text>
					</view>
				</view>
			</view>

		</view>
		<bottomVue value='我的'></bottomVue>
	</view>
</template>

<script>
	const app = getApp().globalData;
	const {
		imgRemote,
	} = app;
	import bottomVue from "@/components/bottom.vue";
	export default {
		components: {
			bottomVue
		},
		data() {
			return {
				userInfo: uni.getStorageSync('userInfo'),
				userToken: uni.getStorageSync('userToken'),
				statusNum: {},
				orderStatu: [],
				shopStatu: [],
				personInfo: '',
				imgRemote: imgRemote,
				service: [],
				site: []
			};
		},
		onLoad() {
			this.getLm();
		},
		onShow: function() {
			let token = uni.getStorageSync('userToken');
			if (token) {
				this.userToken = token;
			} else {
				this.userToken = '';
				this.personInfo = '';
			}
			var that = this;
			if (uni.getStorageSync('userToken')) {
				that.memberInfo();
			}
			this.getfwStu();
			this.getShopStu();
		},
		methods: {
			getShopStu() {
				this.$get(this.$api.shopStu, {}, res => {
					let {
						code,
						data
					} = res.data;
					if (code == 1) {
						this.shopStatu = data;
					}
				});
			},
			getfwStu() {
				this.$get(this.$api.fwStu, {}, res => {
					let {
						code,
						data
					} = res.data;
					if (code == 1) {
						this.orderStatu = data;
					}
				});
			},
			isLogin() {
				this.$needLogin(() => {}, 2, '/pages/tabar/user');
			},
			getLm() {
				this.$get(this.$api.fwLm, {
					type: 2
				}, res => {
					let data = res.data;
					if (data.code == 1) {
						//this.orderStatu = data.data.list;
						this.service = data.data.lists;
					}
				});
			},
			updateAvatar() {
				uni.navigateTo({
					url: '../user/updateavatar'
				})
			},
			remainPage() {
				this.$needLogin(() => {
					uni.navigateTo({
						url: '../user/remainder'
					})
				})
			},
			pageUrl(e) {
				if (e.url) {
					if (e.url == '/pages/wx/login') {
						let token = uni.getStorageSync('wxToken');
						if (token) {
							uni.navigateTo({
								url: '/pages/wx/index'
							});
						} else {
							uni.navigateTo({
								url: e.url
							});
						}
					}else if(e.url == '/pages/keep/login'){
					  	let token = uni.getStorageSync('gdToken');
					  	if (token) {
					  		uni.navigateTo({
					  			url: '/pages/keep/work'
					  		});
					  	} else {
					  		uni.navigateTo({
					  			url: e.url
					  		});
					  	}
					}else if(e.url == '/pages/hx/login'){
					  	let token = uni.getStorageSync('hxToken');
					  	if (token) {
					  		uni.navigateTo({
					  			url: '/pages/hx/index'
					  		});
					  	} else {
					  		uni.navigateTo({
					  			url: e.url
					  		});
					  	}
					}else if (e.type == 1) {

						this.$needLogin(() => {

							uni.navigateTo({
								url: e.url + '?title=' + e.title
							})
						});
					} else {
						this.$needLogin(() => {
							uni.switchTab({
								url: e.url
							})
						});
					}


				} else {
					this.$Toast('该功能暂时还未开放~')
				}
			},
			orderShopPage(e){
				
				if(!isNaN(e.url)){
					uni.navigateTo({
						url: '/pages/tabar/order?status=' + e.url
					})
				}else{
					uni.navigateTo({
						url:e.url
					})
				}
				
			  	
			},
			orderPage(e) {
				
				if(!isNaN(e.url)){
					uni.navigateTo({
						url: '/pages/fw/lists?status=' + e.url
					})
				}else{
					uni.navigateTo({
						url:e.url
					})
				}
				
				/* uni.navigateTo({
					url: '/pages/fw/lists?status=' + e.url
				}) */
			},
			memberInfo() {
				let params = {
					token: uni.getStorageSync('userToken')
				}
				this.$get(this.$api.userInfo, params, (res) => {
					let {
						data
					} = res;
					if (data.code == 1) {
						this.personInfo = data.data;
					}
				})
			},
		},


	};
</script>

<style lang="scss">
	page,
	.user {
		background: #eee;
		/* height: 100%; */
	}

	.avator {
		width: 110rpx;
		height: 110rpx;
		margin: 0rpx 20rpx 0 0;
		border-radius: 50%;
		border: 5rpx solid #DAD9D9;
	}

	.mobile {
		margin-top: 12rpx;
		font-size: 26rpx;
	}

	.set_img {
		width: 50rpx;
	}

	.user .user-back {
		height: 280rpx;
		width: 100%;
		background: linear-gradient(to bottom, #E4B733, #DD7710);
	}

	.user .author {
		.user-level text {
			background: linear-gradient(to right, #FF7D24, #FFB92C);
			color: white;
			border-radius: 6rpx;
			padding: 0rpx 15rpx 2rpx;
			font-size: 22rpx;
			margin-left: 10rpx;
		}

		position: relative;
		top: 0;
		// height: 300rpx;
		color: white;
		padding: 0 30rpx;
		width: 690rpx;

		.un-login {
			display: inline-block;
			font-size: 45px;
			background: rgba(0, 0, 0, 0.2);
			width: 110rpx;
			height: 110rpx;
			margin: 0rpx 20rpx 0 0;
			border-radius: 50%;

			line-height: 110rpx;
			text-align: center;
		}

		.img {
			// height: 294rpx;

			&>view:first-child {
				margin-top: 20rpx;
			}
		}
	}

	.user .back_green {
		background: #094;
		height: 80rpx;
		width: 100%;
	}

	.user .select_operate {
		padding: 0 20rpx;
	}

	.user .select_operate>view {
		height: 98rpx;
		border-bottom: 1px solid #EEE;
		box-sizing: border-box;

		.first-arrow {
			font-size: 50rpx;
			width: 50rpx;
		}

	}

	.user .select_operate>view .name {
		margin-left: 10rpx;

	}


	.user {
		.remain-money {
			box-shadow: 3rpx 4rpx 6px rgba(0, 0, 0, 0.1);
			margin-top: 55rpx;
			border-radius: 10rpx;
			background: white;
			color: black;
			height: 150rpx;
			// line-height: 80rpx;
			padding: 0 80rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			&>view {
				display: flex;
				flex-direction: column;
			}

			text {
				text-align: center;
			}
		}

		.order-info {
			background: white;
			border-radius: 10rpx;
			margin: 30rpx 30rpx 0rpx;
			padding: 0 30rpx 30rpx 30rpx;
			box-shadow: 3rpx 4rpx 6px rgba(0, 0, 0, 0.1);
		}

		.order-info .my-order {
			margin-top: 30rpx;
			height: 91.8rpx;
			line-height: 91.8rpx;
			border-bottom: 1px solid #eee;
		}

		.order-statu {

			flex-basis: 20%;
			margin-top: 10rpx;

			image {
				width: 60rpx;
				height: 60rpx;

			}

			.name {
				margin-top: -5rpx;
			}

			.to-be-paid {
				position: absolute;
				width: 30rpx;
				height: 30rpx;
				 background: #2B63F4;
				color: #fff;
				border-radius: 50%;
				margin: 4rpx 0 0 -15rpx;
				line-height: 30rpx;
				font-size: 22rpx;
				text-align: center;
			}
			
			.paid-red{
				background: red;
			}
			

			.scale {
				width: 50rpx;
			}
		}

		.my-service {

			box-shadow: 3rpx 4rpx 6px rgba(0, 0, 0, 0.1);
			border-radius: 10rpx;
			margin: 30rpx;
			padding: 30rpx;
			background: white;

			image {
				width: 60rpx;
				height: 60rpx;
				margin-bottom: 10rpx;
			}

			.sign {
				flex-wrap: wrap;
				display: flex;

				// flex-direction: column;
				&>view {
					margin-top: 30rpx;
					align-items: center;
					flex-basis: 25%;
					display: flex;
					flex-direction: column;

				}
			}
		}
	}

	.fu_box {
		display: flex;
		align-items: center;
	}

	.user_box {
		position: relative;
		top: -300rpx;
		box-sizing: border-box;
		padding: 50rpx 0 0 0;
	}
</style>